<template>
	<!-- 反馈问题页面 -->
	<view>
		<my-head title="反馈问题" :right="true" text_right="反馈记录" :textrightcolor="textrightcolor"
			@clickRight="clickRight"></my-head>
		<view class="content">
			<view>
				<u--form>
					<u-form-item label="反馈类型" prop="userInfo.sex" borderBottom @click="show = true;" ref="item1"
						label-width="80" required>
						<u--input :value="joblsit2text" disabled disabledColor="#ffffff" placeholder="请选择反馈类型"
							border="none"></u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
					<u-form-item label="问题描述" prop="userInfo.sex" borderBottom ref="item1" label-width="80" required>
						<u--textarea v-model="from.Describe" placeholder="请输入问题描述" count :maxlength='300'
							:height='200'></u--textarea>
					</u-form-item>
					<u-form-item label="图片" prop="userInfo.sex" borderBottom ref="item1" label-width="80">
						<u-upload :fileList="fileList5" @afterRead="afterRead" @delete="deletePic" name="5" multiple
							:maxCount="3" :previewFullImage="true"></u-upload>

						<!-- <view v-if="fileList5" style="position: absolute;left: 47%;bottom: 48%;font-size: 24rpx;">最多上传3张图片</view> -->
					</u-form-item>
					<u-form-item label="联系方式" prop="userInfo.sex" borderBottom ref="item1" label-width="80">
						<u--input v-model="from.Phone" disabledColor="#ffffff" placeholder="请填写联系方式"
							border="none"></u--input>
					</u-form-item>
				</u--form>
			</view>

			<view style="padding: 100rpx 40rpx">
				<u-button type="primary" @click="clicktijiao">提交</u-button>
			</view>

			<u-picker :show="show" :columns="fankuileixing" keyName="text" @close="close" @confirm="confirm"
				@cancel="show=false"></u-picker>

		</view>

	</view>
</template>

<script>
	import myHead from '@/pages/component/baseHead.vue'
	export default {
		data() {
			return {
				title: "反馈问题",
				headImg: [],
				URL: this.$config.domain.staticUrl,
				show: false,
				list: [],
				from: {
					UserId: uni.getStorageSync('homelist').UserInfo.UserId,
					UserName: uni.getStorageSync('homelist').UserInfo.UserName,
					Describe: '', //问题描述
					Picture: '', //图片
					Phone: '', //联系方式
					type: null, //反馈类型,
					CorpId:null,//企业ID
					CorpName:null,//企业名称
				},
				miaoshutext: "",
				shojihao: "",
				tpdz: "",
				textrightcolor: '#1684FC',
				fankuileixing: [],

			}
		},
		components: {
			myHead,
		},
		computed: {
			joblsit2text() {
				let arr = [];
				if (this.fankuileixing.length > 0) {
					arr = this.fankuileixing[0].filter(res => {
						console.log(res);
						return this.from.type == res.value;
					})
				}
				if (arr.length == 0) {
					return ''
				} else {
					return arr[0].text || ' '
				}
			},
			fileList5() {
				let arr = []
				return this.headImg.map(res => {
					arr.push(res)
					this.from.Picture = arr.join(',')
					console.log(this.from);
					return {
						url: this.URL + res
					}
				})
			}
		},
		onShow() {},
		created() {
			this.xialashuju()
		},
		onLoad(option) {
			if(option){
				this.from.CorpId=option.ids
				this.from.CorpName=option.corpnames
			}
		},
		methods: {
			confirm(e) {
				console.log('选择类型', e);
				this.from.type = e.value[0].value
				this.show = false
				console.log(this.from);
			},
			close() {
				this.show = false
			},
			xialashuju() {
				let obj = {}
				let dictionaryTypeld = "408819466735749";
				this.$http.dic.DataSelector(dictionaryTypeld).then(res => {
					console.log(res)
					if (res.Success) {
						this.fankuileixing = this.xialist(res.Result)
					}
				})
			},
			xialist(arr) {
				let drr = [];
				arr.forEach(res => {
					let obj = {
						text: res.FullName,
						value: res.EnCode
					}
					drr.push(obj)
				})
				return [drr]
			},
			// 上传 图片
			afterRead(file, lists, name) {
				var that = this;
				let tempFilePaths = file.file
				console.log(tempFilePaths);
				let obj = {
					src: tempFilePaths[0].url
				}
				console.log(obj);

				that.$util.AuploadFile(obj).then(res => {
					if (res.Success) {
						console.log(res.Result);
						// that.src = res.Result.Path;
						that.headImg.push(res.Result.Path);

					}
				})
			},
			// 删除图片
			deletePic(file, lists, name) {
				console.log(file)
				this.headImg.splice(file.index, 1)
			},

			clicktijiao() {
				if (this.from.type == null) {

					this.$util.toast("请选择反馈类型")
					return;
				}
				if (this.from.Describe.trim().length == '') {
					this.$util.toast('请输入问题描述')
					return
				}
				let email_reg = /^1[3-9]\d{9}$/;
				if (!email_reg.test(this.from.Phone)) {
					this.$util.toast('请输入正确的手机号')
					return
				}
				console.log(this.from)	
				this.$http.huirc.feedbackCorpAdd(this.from).then(res => {
					console.log(res)
					if (res.Success) {
						this.$util.toast(res.Message)
						setTimeout(() => {
							uni.navigateBack();
						}, 1000)
					}
				})

			},


			clickRight() {
				uni.navigateTo({
					url: "/pages/views/packageB/type-recruit/jibenshezhi/feedback/feedbackRecord"
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #fff;
	}
</style>
<style scoped lang="scss">
	.content {
		padding: 30rpx;
		// border-top: 1rpx solid #999999;
	}

	.miaoshu {
		padding: 20rpx 30rpx;
		padding: 20rpx;
		background: #FFFFFF;
	}

	/deep/ .uni-input-placeholder {
		font-size: 30rpx;
	}
</style>